package game.Weapons;

import game.Sprites.SpriteSheet;
import game.Sprites.Transparency;
import net.sf.image4j.codec.bmp.BMPDecoder;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;

public class WeaponSkins {

    static List<SpriteSheet> terroristSkins;
    static List<SpriteSheet> counterSkins;

    static SpriteSheet legsSheet;

    public static void init() throws Exception {
        loadSkins();
    }

    protected static void loadSkins() throws Exception {
        /*
        terroristSkins = new ArrayList<SpriteSheet>(4);
        counterSkins = new ArrayList<SpriteSheet>(4);

        // Load terrorist and counter-terrorist sprite sheets (t1.bmp -> t4.bmp and ct1.bmp -> ct4.bmp)
        String basePath = "Sprites/player/";
        for(int i = 1; i <= 4; i++){
            String ctPath = basePath + "ct"+i+".bmp";
            String tPath = basePath + "t"+i+".bmp";

            // Load counter-terrorist sprite sheet
            BufferedImage ctImg = BMPDecoder.read(game.Player.PlayerSkins.class.getClassLoader().getResourceAsStream(ctPath));
            if(ctImg.getTransparency() == 1){
                // Get transparency from pink background (first pixel)
                ctImg = Transparency.makeBackgroundTransparent(ctImg);
            }

            SpriteSheet ctSheet = new SpriteSheet(ctImg, 2, 3);
            counterSkins.add(ctSheet);

            // Load terrorist sprite sheet
            BufferedImage tImg = BMPDecoder.read(game.Player.PlayerSkins.class.getClassLoader().getResourceAsStream(tPath));
            if(tImg.getTransparency() == 1){
                // Get transparency from pink background (first pixel)
                tImg = Transparency.makeBackgroundTransparent(tImg);
            }
            SpriteSheet tSheet = new SpriteSheet(tImg, 2, 3);
            terroristSkins.add(tSheet);
        }

        // Load legs sprite sheet
        String legsPath = basePath + "legs.bmp";
        BufferedImage legsTrans = BMPDecoder.read(game.Player.PlayerSkins.class.getClassLoader().getResourceAsStream(legsPath));
        if(legsTrans.getTransparency() == 1){
            // Get transparency from pink background (first pixel)
            legsTrans = Transparency.makeBackgroundTransparent(legsTrans);
        }

        legsSheet = new SpriteSheet(legsTrans, 4, 2);

         */
    }

    protected static SpriteSheet getTerroristSkin(int i){
        return terroristSkins.get(i);
    }

    protected static SpriteSheet getCounterSkin(int i){
        return counterSkins.get(i);
    }


    protected static SpriteSheet getRandomCounterSkin(){
        int max = counterSkins.size();
        int rnd = (int)(Math.random() * max); // max not included

        return counterSkins.get(rnd);
    }

    protected static SpriteSheet getRandomTerroristSkin(){
        int max = terroristSkins.size();
        int rnd = (int)(Math.random() * max);// max not included

        return terroristSkins.get(rnd);
    }

    public static SpriteSheet getLegsSheet(){
        return legsSheet;
    }

    public static List<SpriteSheet> getTerroristSkins(){
        return terroristSkins;
    }

    public static List<SpriteSheet> getCounterSkins(){
        return counterSkins;
    }

}

